package com.xinjian.jianba.examples;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.junit.Test;

import com.xinjian.jianba.SpringBootTestCaseBase;
import com.xinjian.jianba.utils.QiNiuUtil;

import sun.misc.BASE64Decoder;

public class up_over extends SpringBootTestCaseBase{

	@Test
	public  void test() throws IOException {
		 String filePath = "C:/Users/10649/Desktop/470d396e46ae95cd925bfa0bd5be14e0.jpg";
		 FileInputStream fileInputStream=new FileInputStream(filePath);
		 byte[] out=toByteArray(fileInputStream);
		@SuppressWarnings("restriction")
		String base64=new sun.misc.BASE64Encoder().encode(out);;
		System.out.println(1);
		System.out.print(base64);
		System.out.println(1);
		@SuppressWarnings("restriction")
		byte[] imgByte = new BASE64Decoder().decodeBuffer(base64); 
		String address=QiNiuUtil.upOverWrite("AC_TEST1", imgByte);
		System.out.println(address);

	}

	private  byte[] toByteArray(InputStream in) throws IOException {
		 
	    ByteArrayOutputStream out = new ByteArrayOutputStream();
	    byte[] buffer = new byte[1024 * 4];
	    int n = 0;
	    while ((n = in.read(buffer)) != -1) {
	        out.write(buffer, 0, n);
	    }
	    return out.toByteArray();
	}
}
